package cn.chenyumeng.blog.controller.blog;

import cn.chenyumeng.blog.dto.BlogDTO;
import cn.chenyumeng.blog.dto.CommonResponse;
import cn.chenyumeng.blog.dto.ResultCode;
import cn.chenyumeng.blog.service.blog.ArchivesPageServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @program: blog->ArchivesPageController
 * @description:
 * @author: cg
 * @create: 2020-08-10 18:32
 **/
@Validated
@RestController
@ResponseBody
@RequestMapping("/blog/archives")
public class ArchivesPageController {

    @Autowired
    private ArchivesPageServer archivesPageServer;

    @GetMapping("/getArchives")
    public CommonResponse getArchives() {
        Map<Integer, List<BlogDTO>> archives = archivesPageServer.getArchives();
        if (archives == null) {
            return CommonResponse.build(ResultCode.PARAM_IS_INVALID);
        }
        return CommonResponse.ok(archives);
    }

}
